package com.lp.compt.controllers;

import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import com.lp.compt.pojo.SsCompetitionEntity;
import com.lp.compt.services.SsCompetitionEntityService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务类
 *
 * @author
 * @since 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping("/ssCompetitionEntity")
public class SsCompetitionEntityController {

    final
    SsCompetitionEntityService ssCompetitionEntityService;

    public SsCompetitionEntityController(SsCompetitionEntityService ssCompetitionEntityService) {
        this.ssCompetitionEntityService = ssCompetitionEntityService;
    }

    /**
     * 根据SsCompetitionEntity的字段,自动生成条件,字段的值为null不生成条件
     * http://localhost:8080/user/?id=1
     *
     * @param ssCompetitionEntity 实体对象
     * @param pageable            分页/排序对象
     * @return 返回的是实体, 里面涵盖分页信息及状态码
     */
    @GetMapping
    ResponseEntity<Object> search(SsCompetitionEntity ssCompetitionEntity, Pageable pageable) {
        return ssCompetitionEntityService.search(ssCompetitionEntity, pageable);
    }

    @GetMapping("all")
    List<SsCompetitionEntity> searchAll() {
        return ssCompetitionEntityService.findAll();
    }

    @PostMapping("save")
    Map create(@RequestBody SsCompetitionEntity entity) {
        ssCompetitionEntityService.save(entity);
        return new HashMap() {
            {
                put("code", 200);
                put("msg", "添加成功");
            }
        };
    }


    @PostMapping("del")
    Map del(@RequestBody SsCompetitionEntity entity) {
        ssCompetitionEntityService.del(entity);
        return new HashMap() {
            {
                put("code", 200);
                put("msg", "添加成功");
            }
        };
    }

    @PutMapping
    void update() {
    }

    @DeleteMapping("/")
    void delete() {
    }
}
